// backend/models/Student.js

const pool = require('../config/db');

class Student {
  // 获取所有学生
  static async getAll() {
    try {
      const [rows] = await pool.query('SELECT * FROM student');
      return rows;
    } catch (error) {
      console.error('获取学生数据失败:', error);
      throw error;
    }
  }

  // 根据ID获取学生
  static async getById(id) {
    try {
      const [rows] = await pool.query('SELECT * FROM student WHERE id = ?', [id]);
      return rows[0];
    } catch (error) {
      console.error(`获取学生ID=${id} 失败:`, error);
      throw error;
    }
  }

}

module.exports = Student;